package muview;

import java.io.File;
import java.sql.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import mumethod.AccessPhysicals;
import mumethod.AccessQuestionnaires;
import mumethod.AccessQuestions;
import mumethod.AccessSchools;
import mumethod.AccessStudents;
import mumethod.Base64String;
import mumethod.DateControl;
import mumethod.ExportFunction;
import mumethod.ImportFunction;
import mumethod.LibFunction;
import mumethod.CountTableRow;
import mumethod.GetSelectYear;
import mumethod.PreviewReport;
import mumethod.PreviewReportService;
import mumethod.ViewFunction;
import muobject.Physical;
import muobject.Question;
import muobject.Questionnaire;
import muobject.School;
import muobject.Student;
import muobject.SystemProperty;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.cloudgarden.resource.SWTResourceManager;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class TeacherDataInput extends Composite {

	{
		SWTResourceManager.registerResourceUser(this);
	}
	
	
	private Label lab_date;
	private Combo cmb_class;
	private Label lab_class;
	private Combo cmb_grade;
	private Label lab_grade;
	private Button but_deletealldate;
	private Button but_setdate;
	private Button but_selectdate;
	private Button but_calendar;
	private Button but_save;
	private Button but_setalldate;
	private Button but_deleteallphysical;
	private Button but_deletephysical;
	private Button but_physicalsave;
	private Button but_physicalexport;
	private Button but_physicalimport;
	private Button but_physicalsample;
	private Button but_questionnaireSave;
	private Button but_question;
	private Button but_questionnaireTemplate;
	private Button but_questionnaireImport;
	private Button but_questionnaireDateAdd;
	private Button but_questionnaireDeleteAll;
	private Combo cmb_date;
	private Label lab_datatitle;
	private Label lab_month;
	private Label lab_student;
	private Label lab_qTestDate;
	private Text txt_qTestDate;
	private Table tableOne;
	private Table tableStudent;
	private Table tableTestDate;
	private Table tableQuestionnarie;
	
	private List<Physical> physicals;
	private List<Questionnaire> questionnaires;
	
	private ApplicationContext springConnector;
	private AccessStudents getStudents;
	private AccessPhysicals getPhysicals;
	private AccessQuestionnaires getQuestionnaires;
	private AccessQuestions getQuestions;
	private List<String> grades;
	private List<String> sclasses;
	private List<String> testDates;
	private String sno;
	private String year;
	private String grade;
	private String sclass;
	private Boolean editFlat;
	private String currentYear;
	private String currentMonth;
	private String imagePath;
	private String templatePath;
	private String selectStudentNo;
	private String selectTestDate;
	private Base64String Base64;
	private Color selectColor;
	private Color nonSelectColor;
	private int selectColumn;
	private Image calendarImage;
	private Shell shell;
	private Combo cmb_month;
	private DateControl dateControl;
	private TableEditor[] answerEditors;
	private Combo[] answerCombos;
	private PreviewReport previewReport;
	private ExportFunction excelExport;
	private ImportFunction excelImport;
	private String TemplatePath;
	
	public void Init(SystemProperty systemProperty, Shell shellLocal) {
		springConnector = systemProperty.getSpringConnector();
		getStudents = (AccessStudents) springConnector
				.getBean("AccessStudentsService");
		getPhysicals = (AccessPhysicals)springConnector
				.getBean("AccessPhysicalsService");
		getQuestionnaires = (AccessQuestionnaires)springConnector
				.getBean("AccessQuestionnairesService");
		getQuestions = (AccessQuestions)springConnector
				.getBean("AccessQuestionsService");
		previewReport = (PreviewReport)springConnector
				.getBean("PreviewReportService");
		year = systemProperty.getYear();
		sno = systemProperty.getSno();
		grade = systemProperty.getGrade();
		sclass = systemProperty.getSclass();
		editFlat = systemProperty.getYear().substring(0, 4)
				.equals(systemProperty.getCurrentYear());
		currentYear = systemProperty.getCurrentYear();
		TemplatePath = systemProperty.getTemplatePath();
		//currentMonth = 
		templatePath = systemProperty.getTemplatePath();
		imagePath = systemProperty.getImagePath();
		Base64 = new LibFunction();
		selectColor = new Color(this.getDisplay(), 135,206,250);
		nonSelectColor = new Color(this.getDisplay(), 255,255,255);
		ImageData date = new ImageData(imagePath + "calendar.png");
		date.scaledTo(10, 10);
		calendarImage = new Image(this.getDisplay(), date);
		shell = shellLocal;
		dateControl = new LibFunction();
		excelExport = new ExportFunction();
		excelImport = new ImportFunction();
		
	}
	
	public TeacherDataInput(Composite c, final Shell shell, final SystemProperty systemProperty) {
		super(c, SWT.BORDER);
		Init(systemProperty, shell);
		FillLayout CompositeFormLayout = new FillLayout();
		this.setLayout(CompositeFormLayout);
		this.setSize(990, 520);
		{
		Composite composite = new Composite(this, SWT.NONE);
		GridLayout compositeLayout = new GridLayout();
		compositeLayout.makeColumnsEqualWidth = true;
		composite.setLayout(compositeLayout);
		{
			GridData upCompositeGridData = new GridData();
			upCompositeGridData.widthHint = 975;
			upCompositeGridData.heightHint = 79;
			Composite upComposite = new Composite(composite, SWT.NONE);
			upComposite.setLayoutData(upCompositeGridData);
			upComposite.setLayout(new FormLayout());
			
			{
				lab_datatitle = new Label(upComposite, SWT.NONE);
				FormData lab_datatitleLData = new FormData();
				lab_datatitleLData.left =  new FormAttachment(0, 1000, 0);
				lab_datatitleLData.top =  new FormAttachment(0, 1000, 0);
				lab_datatitleLData.width = 289;
				lab_datatitleLData.height = 36;
				lab_datatitle.setLayoutData(lab_datatitleLData);
				lab_datatitle.setText("\u9ad4\u9069\u80fd\u53ca\u5fc3\u7406\u6578\u64da\u8f38\u5165");
				lab_datatitle.setFont(SWTResourceManager.getFont("Tahoma", 20, 1, false, false));
			}
			{
				sclasses = getStudents.getAllSclass(sno, year, grade);
				sclasses.add("All");
				cmb_class = new Combo(upComposite, SWT.NONE);
				FormData cmb_classLData = new FormData();
				cmb_classLData.left =  new FormAttachment(0, 1000, 261);
				cmb_classLData.top =  new FormAttachment(0, 1000, 45);
				cmb_classLData.width = 121;
				cmb_classLData.height = 20;
				cmb_class.setLayoutData(cmb_classLData);
				for (String str : sclasses) {
					cmb_class.add(str);
				}
				cmb_class.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						sclass = cmb_class.getText().equals("All") ? "%"
								: cmb_class.getText();
						testDates = getPhysicals.getAllTestDate(sno, year, grade, sclass);
						cmb_date.removeAll();
						for (String str : testDates) {
							cmb_date.add(str);
						}
						if(cmb_date.getItemCount() > 0)
							cmb_date.select(0);
						tableOne.removeAll();
						tableStudent.removeAll();
						tableOneGetData();
						tableStudentGetData();
					}
				});
			}
			{
				lab_class = new Label(upComposite, SWT.NONE);
				FormData lab_classLData = new FormData();
				lab_classLData.left =  new FormAttachment(0, 1000, 205);
				lab_classLData.top =  new FormAttachment(0, 1000, 42);
				lab_classLData.width = 50;
				lab_classLData.height = 25;
				lab_class.setLayoutData(lab_classLData);
				lab_class.setText("\u73ed\u5225 :");
				lab_class.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
			}
			{
				grades = getStudents.getAllGrade(sno, year, sclass);
				grades.add("All");
				cmb_grade = new Combo(upComposite, SWT.NONE);
				FormData cmb_gradeLData = new FormData();
				cmb_gradeLData.left =  new FormAttachment(0, 1000, 56);
				cmb_gradeLData.top =  new FormAttachment(0, 1000, 45);
				cmb_gradeLData.width = 113;
				cmb_gradeLData.height = 20;
				cmb_grade.setLayoutData(cmb_gradeLData);
				for (String str : grades) {
					cmb_grade.add(str);
				}
				cmb_grade.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						grade = cmb_grade.getText().equals("All") ? "%"
								: cmb_grade.getText();
						sclass = "%";
						sclasses = getStudents.getAllSclass(sno, year, grade);
						sclasses.add("All");
						testDates = getPhysicals.getAllTestDate(sno, year, grade, sclass);
						cmb_class.removeAll();
						cmb_date.removeAll();
						for (String str : sclasses) {
							cmb_class.add(str);
						}
						for (String str : testDates) {
							cmb_date.add(str);
						}
						if(cmb_date.getItemCount() > 0)
							cmb_date.select(0);
						tableOne.removeAll();
						tableStudent.removeAll();
						tableOneGetData();
						tableStudentGetData();
					}
				});
			}
			{
				lab_grade = new Label(upComposite, SWT.NONE);
				FormData lab_gradeLData = new FormData();
				lab_gradeLData.left =  new FormAttachment(0, 1000, 0);
				lab_gradeLData.top =  new FormAttachment(0, 1000, 42);
				lab_gradeLData.width = 50;
				lab_gradeLData.height = 25;
				lab_grade.setLayoutData(lab_gradeLData);
				lab_grade.setText("\u5e74\u7d1a :");
				lab_grade.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
			}
		}
		{
			GridData pageCompositeGridData = new GridData();
			pageCompositeGridData.widthHint = 975;
			pageCompositeGridData.heightHint = 430;
			Composite pageComposite = new Composite(composite, SWT.NONE);
			pageComposite.setLayoutData(pageCompositeGridData);
			pageComposite.setLayout(new FillLayout());
			{
				final CTabFolder tabpageFolder = new CTabFolder(pageComposite,
						SWT.BORDER);
				tabpageFolder.setSimple(false);
				tabpageFolder.setBackgroundMode(SWT.INHERIT_DEFAULT);
				CTabItem one = new CTabItem(tabpageFolder, SWT.NONE);
				one.setText("輸入體適能測試數據   ");
				one.setToolTipText("");
				one.setFont(SWTResourceManager.getFont("Tahoma", 12, 1, false,
						false));
				one.setControl(gettabpageOneControl(tabpageFolder));

				CTabItem two = new CTabItem(tabpageFolder, SWT.NONE);
				two.setText("輸入運動及飲食習慣   ");
				two.setToolTipText("");
				two.setFont(SWTResourceManager.getFont("Tahoma", 12, 1, false,
						false));
				two.setControl(gettabpagetwoControl(tabpageFolder));

				tabpageFolder.setSelection(0);
			}
		}
		}
	}
	
	private Composite gettabpageOneControl(CTabFolder tabpageFolder) {
		Composite pagePhysicalComposite;
		pagePhysicalComposite = new Composite(tabpageFolder, SWT.NONE);
		GridLayout pagePhysicalCompositeLayout = new GridLayout();
		pagePhysicalCompositeLayout.makeColumnsEqualWidth = true;
		pagePhysicalCompositeLayout.numColumns = 8;
		pagePhysicalComposite.setLayout(pagePhysicalCompositeLayout);
		{
			{
				GridData lab_dateLData = new GridData();
				lab_dateLData.horizontalSpan = 1;
				lab_dateLData.verticalAlignment = GridData.END;
				lab_date = new Label(pagePhysicalComposite, SWT.NONE);
				lab_date.setLayoutData(lab_dateLData);
				lab_date.setText("\u9078\u64c7\u65e5\u671f :");
				lab_date.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
			}
			{
				GridData cmb_dateLData = new GridData();
				cmb_dateLData.horizontalSpan = 1;
				cmb_dateLData.verticalAlignment = GridData.END;
				cmb_dateLData.widthHint = 100;
				testDates = getPhysicals.getAllTestDate(sno, year, grade, sclass);
				cmb_date = new Combo(pagePhysicalComposite, SWT.None);
				cmb_date.setLayoutData(cmb_dateLData);
				for (String str : testDates) {
					cmb_date.add(str);
				}
				if(cmb_date.getItemCount() > 0)
				cmb_date.select(0);
				cmb_date.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						tableOne.removeAll();
						tableOneGetData();
					}
				});
			}
			{
				GridData but_calendarLData = new GridData();
				but_calendarLData.horizontalSpan = 1;
				but_calendarLData.verticalAlignment = GridData.END;
				but_calendarLData.widthHint = 20;
				but_calendarLData.heightHint = 20;
				but_calendar = new Button(pagePhysicalComposite, SWT.PUSH | SWT.CENTER);
				but_calendar.setLayoutData(but_calendarLData);
				but_calendar.setImage(calendarImage);
				but_calendar.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						DialogCalendar dialogCalendar = new DialogCalendar(shell);
						Object day = dialogCalendar.open(0,0);
						if(day != null){
							if(dateControl.getDataYear(dateControl.getStringDate(day.toString())).equals(currentYear)){
								cmb_date.setText(day != null ? day.toString() : cmb_date.getText());
							}
						}
					}
				});
			}
			{
				GridData but_selectdateLData = new GridData();
				but_selectdateLData.horizontalSpan = 1;
				but_selectdateLData.verticalAlignment = GridData.END;
				but_selectdate = new Button(pagePhysicalComposite, SWT.PUSH | SWT.CENTER);
				but_selectdate.setLayoutData(but_selectdateLData);
				but_selectdate.setText("\u52a0\u5165\u6aa2\u6e2c\u65e5\u671f");
				but_selectdate.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_selectdate.setSize(144, 29);
				but_selectdate.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						tableOne.removeAll();
						tableOneGetData();
					}
				});
			}
			{
				GridData but_setalldateLData = new GridData();
				but_setalldateLData.horizontalSpan = 1;
				but_setalldateLData.verticalAlignment = GridData.END;
				but_setalldate = new Button(pagePhysicalComposite, SWT.PUSH | SWT.CENTER);
				but_setalldate.setLayoutData(but_setalldateLData);
				but_setalldate.setText("\u5168\u90e8\u65e5\u671f\u5957\u7528");
				but_setalldate.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_setalldate.setSize(144, 29);
				but_setalldate.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						for(TableItem tableItem : tableOne.getItems()){
							tableItem.setText(1, cmb_date.getText());
						}
					}
				});
			}
			{
				GridData but_setdateLData = new GridData();
				but_setdateLData.horizontalSpan = 3;
				but_setdateLData.verticalAlignment = GridData.END;
				but_setdate = new Button(pagePhysicalComposite, SWT.PUSH | SWT.CENTER);
				but_setdate.setLayoutData(but_setdateLData);
				but_setdate.setText("\u6240\u9078\u65e5\u671f\u5957\u7528");
				but_setdate.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_setdate.setSize(144, 29);
				but_setdate.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						tableOne.getItem(selectColumn).setText(1, cmb_date.getText());
					}
				});
			}
			{
				GridData tableOneLData = new GridData();
				tableOneLData.horizontalSpan = 8;
				tableOneLData.verticalAlignment = GridData.END;
				tableOneLData.widthHint = 940;
				tableOneLData.heightHint = 285;
				tableOne = new Table(pagePhysicalComposite, SWT.CHECK
						| SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
				tableOne.setHeaderVisible(true);
				tableOne.setLinesVisible(true);
				tableOne.setFont(SWTResourceManager.getFont("Tahoma", 9, 0, false,
						false));
				tableOne.setLayoutData(tableOneLData);
				{
					String[] titles = { "禁止修改", "測試日期","學生編號", "班級", "班別", "班號", "姓名",
							"姓別", "身高(cm)", "體重(kg)", "手握力(kg)", "立定跳遠(cm)",
							"坐位體前屈(cm)", "肺活量(L)", "6/9分鐘跑", "15米來回跑" };

					for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
						TableColumn column = new TableColumn(tableOne, SWT.NULL);
						column.setText(titles[loopIndex]);
					}
					TableColumn column = new TableColumn(tableOne, SWT.NULL);
					column.setWidth(0);
					column.setResizable(false);

					tableOneGetData();
					
					for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
						tableOne.getColumn(loopIndex).pack();
					}

					final TableEditor editor = new TableEditor(tableOne);
					editor.horizontalAlignment = SWT.LEFT;
					editor.grabHorizontal = true;
					if(year.equals(currentYear))
						tableOne.addMouseListener(new MouseAdapter() {
						public void mouseDown(MouseEvent event) {
							Rectangle clientArea = tableOne.getClientArea();
							Point pt = new Point(event.x, event.y);
							int index = tableOne.getTopIndex();
							while (index < tableOne.getItemCount()) {
								boolean visible = false;
								final TableItem item = tableOne.getItem(index);
								final int indexNow = index;
								for (int i = 0; i < tableOne.getColumnCount(); i++) {
									Rectangle rect = item.getBounds(i);
									if (rect.contains(pt)) {
										final Text text = new Text(tableOne,
												SWT.NONE);
										final CountTableRow countTableRow = new ViewFunction();
										countTableRow.setTableRowCount(0);
										Listener textListener = new Listener() {
											public void handleEvent(
													final Event e) {
												switch (e.type) {
												case SWT.FocusOut:
													tableOne.getItem(indexNow + countTableRow.getTableRowCount())
															.setText(editor.getColumn(),text.getText());
													tableOne.getItem(indexNow + countTableRow.getTableRowCount())
															.setBackground(nonSelectColor);
													text.dispose();
													break;
												case SWT.Traverse:
													int blockRow = 0;
													switch (e.detail) {
													case SWT.TRAVERSE_RETURN:
														if (indexNow + countTableRow.getTableRowCount() + 1 >= tableOne
																.getItemCount())
															break;
														for (int i = countTableRow.getTableRowCount(); i <= tableOne
																.getItemCount(); i++) {countTableRow.addTableColumnCount();
															blockRow += 1;
															tableOne.getItem(indexNow + countTableRow.getTableRowCount() - blockRow)
																	.setText(editor.getColumn(),text.getText());
															if (countTableRow.getTableRowCount() >= tableOne.getColumnCount()) {
																break;
															}
															if (!tableOne.getItem(indexNow + countTableRow.getTableRowCount())
																	.getChecked()) {editor.setEditor(text,tableOne.getItem(indexNow
																				+ countTableRow.getTableRowCount()),8);
																text.setText(tableOne.getItem(indexNow + countTableRow.getTableRowCount())
																		.getText(8));
																text.selectAll();
																text.setFocus();
																tableOne.getItem(indexNow + countTableRow.getTableRowCount() - blockRow)
																		.setBackground(nonSelectColor);
																tableOne.getItem(indexNow + countTableRow.getTableRowCount())
																		.setBackground(selectColor);
																selectColumn = indexNow + countTableRow.getTableRowCount();
																break;
															} else {
																continue;
															}
														}
														break;
													case SWT.TRAVERSE_ESCAPE:
														text.dispose();
														e.doit = false;
														selectColumn = -1;
														break;
													case SWT.TRAVERSE_TAB_NEXT:
														if (editor.getColumn() + 2 == tableOne
																.getColumnCount()) {
															if (indexNow + countTableRow.getTableRowCount() + 1 >= tableOne
																	.getItemCount())
																break;
															for (int i = countTableRow.getTableRowCount(); i <= tableOne
																	.getItemCount(); i++) {countTableRow.addTableColumnCount();
																blockRow += 1;
																tableOne.getItem(indexNow + countTableRow.getTableRowCount() - blockRow)
																		.setText(editor.getColumn(), text.getText());
																if (!tableOne.getItem(indexNow + countTableRow.getTableRowCount()).getChecked()) {
																	editor.setEditor(text, tableOne.getItem(indexNow + countTableRow.getTableRowCount()),8);
																	text.setText(tableOne.getItem(indexNow + countTableRow.getTableRowCount())
																			.getText(8));
																	text.selectAll();
																	text.setFocus();
																	tableOne.getItem(indexNow + countTableRow.getTableRowCount() - blockRow)
																			.setBackground(nonSelectColor);
																	tableOne.getItem(indexNow + countTableRow.getTableRowCount())
																			.setBackground(selectColor);
																	selectColumn = indexNow + countTableRow.getTableRowCount();
																	break;
																} else {
																	continue;
																}
															}
															e.doit = false;
															e.detail = SWT.TRAVERSE_NONE;
														} else {
															tableOne.getItem(indexNow + countTableRow.getTableRowCount())
																	.setText(editor.getColumn(), text.getText());
															editor.setEditor(text, tableOne.getItem(indexNow + countTableRow.getTableRowCount()), editor.getColumn() + 1);
															text.setText(tableOne.getItem(indexNow + countTableRow.getTableRowCount())
																	.getText(editor.getColumn()));
															text.selectAll();
															text.setFocus();
															selectColumn = indexNow + countTableRow.getTableRowCount();
															e.doit = false;
															e.detail = SWT.TRAVERSE_NONE;
														}
														break;
													}
													break;
												}
											}
										};
										text.addListener(SWT.FocusOut,
												textListener);
										text.addListener(SWT.Traverse,
												textListener);
										if (!(tableOne.getItem(indexNow + countTableRow.getTableRowCount())
												.getChecked()) & i > 7) {
											item.setBackground(selectColor);
											editor.setEditor(text, item, i);
											text.setText(item.getText(i));
											text.selectAll();
											text.setFocus();
										}else if (!(tableOne.getItem(indexNow + countTableRow.getTableRowCount())
												.getChecked()) & i == 0){
											item.setBackground(selectColor);
										}
										selectColumn = indexNow + countTableRow.getTableRowCount();
										return;
									}
									if (!visible && rect.intersects(clientArea)) {
										visible = true;
									}
								}
								if (!visible)
									return;
								index++;
							}
						}
					});
				}
			}
			{
				Composite bottomComposite = new Composite(pagePhysicalComposite, SWT.NONE);
				GridData bottomCompositeLData = new GridData();
				bottomCompositeLData.horizontalSpan = 8;
				bottomCompositeLData.widthHint = 935;
				bottomCompositeLData.heightHint = 50;
				bottomComposite.setLayoutData(bottomCompositeLData);
				bottomComposite.setLayout(new RowLayout());
				{
					but_deleteallphysical = new Button(bottomComposite, SWT.PUSH
							| SWT.CENTER);
					but_deleteallphysical.setText("\u522a\u9664\u6b64\u9801\u8cc7\u6599");
					but_deleteallphysical.setFont(SWTResourceManager.getFont(
							"Tahoma", 16, 1, false, false));
					but_deleteallphysical
							.addSelectionListener(new SelectionAdapter() {
								public void widgetSelected(SelectionEvent e) {
									if(DialogQuestion.open(shell, "確定刪除此頁資料??","確定刪除此頁資料??", SWT.ICON_QUESTION)){
										try{
											if(getPhysicals.deletePhysicalFromTable(tableOne, year)){
												DialogMessage.open(shell, "刪除成功", "刪除成功", SWT.ICON_INFORMATION);
												cmbLoad();
												tableOne.removeAll();
												tableOneGetData();
											}
										}catch (Exception ex){
											DialogMessage.open(shell, "儲存失敗","儲存失敗", SWT.ICON_WARNING);
										}
									}
								}
							});
				}
				{
					but_deletephysical = new Button(bottomComposite, SWT.PUSH | SWT.CENTER);
					but_deletephysical.setText("\u522a\u9664\u6240\u9078\u8cc7\u6599");
					but_deletephysical.setFont(SWTResourceManager.getFont(
							"Tahoma", 16, 1, false, false));
					but_deletephysical
					.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent e) {
							if(DialogQuestion.open(shell, "確定刪除此資料??","確定刪除此資料??", SWT.ICON_QUESTION)){
								try{
									String stno = tableOne.getItem(selectColumn).getText(2);
									String testDate = tableOne.getItem(selectColumn).getText(1);
									if(getPhysicals.deletePhysicalByPar(stno, year, testDate)){
										DialogMessage.open(shell, "刪除成功", "刪除成功", SWT.ICON_INFORMATION);
										cmbLoad();
										tableOne.removeAll();
										tableOneGetData();
									}
								}catch(Exception ex){
									DialogMessage.open(shell, "儲存失敗","儲存失敗", SWT.ICON_WARNING);
								}
							}
							
						}
					});
				}
				{
					but_physicalsample = new Button(bottomComposite, SWT.PUSH | SWT.CENTER);
					but_physicalsample.setText("\u8cc7\u6599\u683c\u5f0f");
					but_physicalsample.setFont(SWTResourceManager.getFont(
							"Tahoma", 16, 1, false, false));
					but_physicalsample
					.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent e) {
							FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
							fileDialog.setText("Save");
							fileDialog.setFilterPath("C:/");
							fileDialog.setFileName("Physical.xls");
					        String[] filterExt = { "*.xls" };
					        fileDialog.setFilterExtensions(filterExt);
					        String distinationPath = fileDialog.open();
					        if(distinationPath != null){
					        	 File file = new File(distinationPath);
							     if(distinationPath != null){
							        if (file.exists()) {
								        if (DialogQuestion.open(shell, "已存在。\n要覆蓋嗎？","確定覆蓋??", SWT.ICON_QUESTION)) {
								        	if(excelExport.ExportPhysicalTemplateExcel(tableOne, distinationPath)){
										      	DialogMessage.open(shell, "儲存成功","儲存成功", SWT.ICON_INFORMATION);
										    }
								        }
								    }else if(distinationPath != null) {
								        if(excelExport.ExportPhysicalTemplateExcel(tableOne, distinationPath)){
									        DialogMessage.open(shell, "儲存成功","儲存成功", SWT.ICON_INFORMATION);
									    }
								    }
							    }
					        }
					       
						}
					});
				}
				{
					but_physicalimport = new Button(bottomComposite, SWT.PUSH | SWT.CENTER);
					but_physicalimport.setText("\u8cc7\u6599\u532f\u5165");
					but_physicalimport.setFont(SWTResourceManager.getFont(
							"Tahoma", 16, 1, false, false));
					but_physicalimport
					.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent e) {
							DialogExcelPath dialogExcelPathnew = new DialogExcelPath(shell);
							String excelPath = dialogExcelPathnew.open();
							String presult;
							if(!excelPath.equals("")){
								tableOne.removeAll();
								presult = excelImport.ImportPhysicalExcel(excelPath, tableOne, year);
								if(!presult.equals("")){
									DialogMessage.open(shell, presult,"格式錯誤", SWT.ICON_WARNING);
								}
							}
						}
					});
				}
				{
					but_physicalexport = new Button(bottomComposite, SWT.PUSH | SWT.CENTER);
					but_physicalexport.setText("\u8cc7\u6599\u8f38\u51fa");
					but_physicalexport.setFont(SWTResourceManager.getFont(
							"Tahoma", 16, 1, false, false));
					but_physicalexport
					.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent e) {
							FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
							fileDialog.setText("Save");
							fileDialog.setFilterPath("C:/");
							fileDialog.setFileName("體適能資料.xls");
					        String[] filterExt = { "*.xls" };
					        fileDialog.setFilterExtensions(filterExt);
					        String distinationPath = fileDialog.open();
					        if(distinationPath != null){
					        	File file = new File(distinationPath);
						        if (file.exists()) {
						        	if (DialogQuestion.open(shell, "已存在。\n要覆蓋嗎？","確定覆蓋??", SWT.ICON_QUESTION)) {
						        		excelExport.ExportTableExcel(tableOne, distinationPath, "體適能資料");
						        	}
						        }else if(distinationPath != null) {
						        	excelExport.ExportTableExcel(tableOne, distinationPath, "體適能資料");
						        }
					        }
						}
					});
				}
				{
					but_physicalsave = new Button(bottomComposite, SWT.PUSH | SWT.CENTER);
					but_physicalsave.setText("\u5132\u5b58\u8cc7\u6599");
					but_physicalsave.setFont(SWTResourceManager.getFont(
							"Tahoma", 16, 1, false, false));
					but_physicalsave
					.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent e) {
							if(DialogQuestion.open(shell, "確定儲存資料??","確定儲存資料??", SWT.ICON_QUESTION)){
								try{
									if(getPhysicals.setPhysicalFromTable(tableOne, year)){
										DialogMessage.open(shell, "儲存成功", "儲存成功", SWT.ICON_INFORMATION);
										cmbLoad();
										tableOne.removeAll();
										tableOneGetData();
									}
								}catch(Exception ex){
									DialogMessage.open(shell, "儲存失敗","儲存失敗", SWT.ICON_WARNING);
								}
							}
						}
					});
				}
				
			}
		}
		return pagePhysicalComposite;
	}
	
	private Composite gettabpagetwoControl(CTabFolder tabpageFolder) {
		Composite pageQuestionnaireComposite;
		pageQuestionnaireComposite = new Composite(tabpageFolder, SWT.NONE);
		FormLayout pageQuestionnairCompositeLayout = new FormLayout();
		pageQuestionnaireComposite.setLayout(pageQuestionnairCompositeLayout);
		pageQuestionnaireComposite.setSize(990, 507);
		{
			{
				FormData lab_monthLData = new FormData();
				lab_monthLData.width = 93;
				lab_monthLData.height = 23;
				lab_monthLData.left =  new FormAttachment(0, 1000, 22);
				lab_monthLData.top =  new FormAttachment(0, 1000, 12);
				lab_month = new Label(pageQuestionnaireComposite, SWT.NONE);
				lab_month.setLayoutData(lab_monthLData);
				lab_month.setText("\u9078\u64c7\u6708\u4efd :");
				lab_month.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
			}
			{
				FormData cmb_monthLData = new FormData();
				cmb_monthLData.width = 64;
				cmb_monthLData.height = 24;
				cmb_monthLData.left =  new FormAttachment(0, 1000, 121);
				cmb_monthLData.top =  new FormAttachment(0, 1000, 12);
				cmb_month = new Combo(pageQuestionnaireComposite, SWT.NONE);
				cmb_month.setLayoutData(cmb_monthLData);
				for(int i=1; i<=12; i++){
					cmb_month.add(String.valueOf(i));
				}
				cmb_month.select(dateControl.getCurrentMonth()-1);
				cmb_month.addSelectionListener(new SelectionAdapter() {
				      public void widgetSelected(SelectionEvent e) {
				    	  tableQuestionnairHide();
				    	  tableQuestionnaireTestDateGetData();
				    	  tableQuestionnaireGetData();
				      }
				});
			}
			{
				final List<Question> questions = getQuestions.getQuestionByYear(year);
				FormData but_questionLData = new FormData();
				but_questionLData.width = 108;
				but_questionLData.height = 40;
				but_questionLData.left =  new FormAttachment(0, 1000, 840);
				but_questionLData.top =  new FormAttachment(0, 1000, 12);
				but_question = new Button(pageQuestionnaireComposite, SWT.NONE);
				but_question.setLayoutData(but_questionLData);
				but_question.setText("\u554f\u5377\u5167\u5bb9");
				but_question.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_question.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						try {
							previewReport.QuestionDisplay(questions);
						} catch (Exception e1) {
							e1.printStackTrace();
						}
					}
				});
			}
			{
				final List<Question> questions = getQuestions.getQuestionByYear(year);
				FormData but_questionnaireImportLData = new FormData();
				but_questionnaireImportLData.width = 108;
				but_questionnaireImportLData.height = 40;
				but_questionnaireImportLData.left =  new FormAttachment(0, 1000, 726);
				but_questionnaireImportLData.top =  new FormAttachment(0, 1000, 12);
				but_questionnaireImport = new Button(pageQuestionnaireComposite, SWT.NONE);
				but_questionnaireImport.setLayoutData(but_questionnaireImportLData);
				but_questionnaireImport.setText("\u8cc7\u6599\u532f\u5165");
				but_questionnaireImport.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_questionnaireImport.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						DialogExcelPath dialogExcelPathnew = new DialogExcelPath(shell);
						String excelPath = dialogExcelPathnew.open();
						String qresult = excelImport.ImportQuestionnaireExcel(excelPath, year, questions, getQuestionnaires);
						if(!excelPath.equals("")){
							if(!qresult.equals("")){
								DialogMessage.open(shell, qresult,"格式錯誤", SWT.ICON_WARNING);
							}else{
								DialogMessage.open(shell, "儲存成功","儲存成功", SWT.ICON_INFORMATION);
							}
						}
					}
				});
			}
			
			{
				final List<Question> questions = getQuestions.getQuestionByYear(year);
				FormData but_questionnaireTemplateLData = new FormData();
				but_questionnaireTemplateLData.width = 108;
				but_questionnaireTemplateLData.height = 40;
				but_questionnaireTemplateLData.left =  new FormAttachment(0, 1000, 612);
				but_questionnaireTemplateLData.top =  new FormAttachment(0, 1000, 12);
				but_questionnaireTemplate = new Button(pageQuestionnaireComposite, SWT.NONE);
				but_questionnaireTemplate.setLayoutData(but_questionnaireTemplateLData);
				but_questionnaireTemplate.setText("\u8cc7\u6599\u683c\u5f0f");
				but_questionnaireTemplate.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_questionnaireTemplate.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						try {
							FileDialog fileDialog = new FileDialog(shell, SWT.SAVE);
							fileDialog.setText("Save");
							fileDialog.setFilterPath("C:/");
							fileDialog.setFileName("Questionnaire.xls");
					        String[] filterExt = { "*.xls" };
					        fileDialog.setFilterExtensions(filterExt);
					        String distinationPath = fileDialog.open();
					        if(distinationPath != null){
					        	 File file = new File(distinationPath);
							     if(distinationPath != null){
							        if (file.exists()) {
								        if (DialogQuestion.open(shell, "已存在。\n要覆蓋嗎？","確定覆蓋??", SWT.ICON_QUESTION)) {
								        	if(excelExport.ExportQuestionnaireTemplateExcel(tableStudent, questions, distinationPath)){
										      	DialogMessage.open(shell, "儲存成功","儲存成功", SWT.ICON_INFORMATION);
										    }
								        }
								    }else if(distinationPath != null) {
								        if(excelExport.ExportQuestionnaireTemplateExcel(tableStudent, questions, distinationPath)){
									        DialogMessage.open(shell, "儲存成功","儲存成功", SWT.ICON_INFORMATION);
									    }
								    }
							    }
					        }
							
						} catch (Exception e1) {
							e1.printStackTrace();
						}
					}
				});
			}
			{
				FormData lab_studentLData = new FormData();
				lab_studentLData.width = 93;
				lab_studentLData.height = 23;
				lab_studentLData.left =  new FormAttachment(0, 1000, 22);
				lab_studentLData.top =  new FormAttachment(0, 1000, 39);
				lab_student = new Label(pageQuestionnaireComposite, SWT.NONE);
				lab_student.setLayoutData(lab_studentLData);
				lab_student.setText("\u9078\u64c7\u5b78\u751f :");
				lab_student.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
			}
			{
				FormData lab_qTestDateLData = new FormData();
				lab_qTestDateLData.width = 87;
				lab_qTestDateLData.height = 23;
				lab_qTestDateLData.left =  new FormAttachment(0, 1000, 459);
				lab_qTestDateLData.top =  new FormAttachment(0, 1000, 39);
				lab_qTestDate = new Label(pageQuestionnaireComposite, SWT.NONE);
				lab_qTestDate.setLayoutData(lab_qTestDateLData);
				lab_qTestDate.setText("\u8abf\u67e5\u65e5\u671f:");
				lab_qTestDate.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
			}
			{
				FormData tableStudentLData = new FormData();
				tableStudentLData.width = 402;
				tableStudentLData.height = 298;
				tableStudentLData.left =  new FormAttachment(0, 1000, 22);
				tableStudentLData.top =  new FormAttachment(0, 1000, 70);
				tableStudent = new Table(pageQuestionnaireComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
				tableStudent.setHeaderVisible(true);
				tableStudent.setLinesVisible(true);
				tableStudent.setFont(SWTResourceManager.getFont("Tahoma", 9, 0, false,
						false));
				tableStudent.setLayoutData(tableStudentLData);
				{
					String[] studentTitles = { "班級", "班別", "班號", "名稱", "英文名稱", "學生編號" };

					TableColumn column = new TableColumn(tableStudent, SWT.NULL);
					column.setWidth(0);
					
					for (int loopIndex = 1; loopIndex <= studentTitles.length; loopIndex++) {
						column = new TableColumn(tableStudent, SWT.NULL);
						column.setText(studentTitles[loopIndex-1]);
						if(loopIndex<=4)
							column.setWidth(50);
						else
							column.setWidth(110);
					}

					tableStudentGetData();
					
					tableStudent.addMouseListener(new MouseAdapter() {
						public void mouseDown(MouseEvent event) {
							Point pt = new Point(event.x, event.y);
							int index = tableStudent.getTopIndex();
							while (index < tableStudent.getItemCount()) {
								final TableItem item = tableStudent.getItem(index);
								item.setBackground(nonSelectColor);
								for (int i = 0; i < tableStudent.getColumnCount(); i++) {
									Rectangle rect = item.getBounds(i);
									if (rect.contains(pt)) {
										item.setBackground(selectColor);
										selectStudentNo = item.getText(6);
										tableQuestionnairHide();
										tableQuestionnaireTestDateGetData();
									}
								}
								index++;
							}
						}
					});
				}
			}
			{
				FormData tableTestDateLData = new FormData();
				tableTestDateLData.width = 178;
				tableTestDateLData.height = 262;
				tableTestDateLData.left =  new FormAttachment(0, 1000, 459);
				tableTestDateLData.top =  new FormAttachment(0, 1000, 70);
				tableTestDate = new Table(pageQuestionnaireComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
				tableTestDate.setHeaderVisible(true);
				tableTestDate.setLinesVisible(true);
				tableTestDate.setFont(SWTResourceManager.getFont("Tahoma", 12, 0, false, false));
				tableTestDate.setLayoutData(tableTestDateLData);
				{
					TableColumn column = new TableColumn(tableTestDate, SWT.NULL);
					column.setWidth(0);
					
					column = new TableColumn(tableTestDate, SWT.NULL);
					column.setText("測試日期");
					column.setWidth(230);
					
					tableTestDate.addMouseListener(new MouseAdapter() {
						public void mouseDown(MouseEvent event) {
							Point pt = new Point(event.x, event.y);
							int index = tableTestDate.getTopIndex();
							while (index < tableTestDate.getItemCount()) {
								final TableItem item = tableTestDate.getItem(index);
								item.setBackground(nonSelectColor);
								for (int i = 0; i < tableTestDate.getColumnCount(); i++) {
									Rectangle rect = item.getBounds(i);
									if (rect.contains(pt)) {
										item.setBackground(selectColor);
										selectTestDate = item.getText(1);
										tableQuestionnarie.removeAll();
										tableQuestionnaireGetData();
										tableQuestionnairShow();
									}
								}
								index++;
							}
						}
					});
				}
			}
			{
				FormData tableQuestionnarieLData = new FormData();
				tableQuestionnarieLData.width = 263;
				tableQuestionnarieLData.height = 262;
				tableQuestionnarieLData.left =  new FormAttachment(0, 1000, 668);
				tableQuestionnarieLData.top =  new FormAttachment(0, 1000, 70);
				tableQuestionnarie = new Table(pageQuestionnaireComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
				tableQuestionnarie.setHeaderVisible(true);
				tableQuestionnarie.setLinesVisible(true);
				tableQuestionnarie.setFont(SWTResourceManager.getFont("Tahoma", 12, 0, false, false));
				tableQuestionnarie.setLayoutData(tableQuestionnarieLData);
				{
					TableColumn column = new TableColumn(tableQuestionnarie, SWT.NULL);
					column.setText("問題");
					column.setWidth(100);
					column = new TableColumn(tableQuestionnarie, SWT.NULL);
					column.setText("答案");
					column.setWidth(200);
					
					tableQuestionnairSetup();
					tableQuestionnairHide();
				}
			}
			{
				FormData txt_qTestDateLData = new FormData();
				txt_qTestDateLData.width = 82;
				txt_qTestDateLData.height = 24;
				txt_qTestDateLData.left =  new FormAttachment(0, 1000, 461);
				txt_qTestDateLData.top =  new FormAttachment(0, 1000, 360);
				txt_qTestDate = new Text(pageQuestionnaireComposite, SWT.BORDER);
				txt_qTestDate.setLayoutData(txt_qTestDateLData);
				txt_qTestDate.setFont(SWTResourceManager.getFont("Arial", 9, 1, false, false));
				
				txt_qTestDate.addMouseListener(new MouseAdapter() {
					public void mouseDown(MouseEvent event) {
						DialogCalendar dialogCalendar = new DialogCalendar(shell);
						int selectmonth = Integer.valueOf(cmb_month.getText());
						int selectyear = dateControl.getYearByMonth(Integer.valueOf(year), selectmonth);
						Object day = dialogCalendar.open(selectyear, selectmonth);
						if(day != null){
							if(dateControl.getDataYear(dateControl.getStringDate(day.toString())).equals(currentYear)){
								txt_qTestDate.setText(day != null ? day.toString() : txt_qTestDate.getText());
								but_questionnaireDateAdd.setFocus();
							}
						}
					}
				});
			}
			{
				FormData but_questionnaireDateAddLData = new FormData();
				but_questionnaireDateAddLData.width = 106;
				but_questionnaireDateAddLData.height = 33;
				but_questionnaireDateAddLData.left =  new FormAttachment(0, 1000, 554);
				but_questionnaireDateAddLData.top =  new FormAttachment(0, 1000, 359);
				but_questionnaireDateAdd = new Button(pageQuestionnaireComposite, SWT.NONE);
				but_questionnaireDateAdd.setLayoutData(but_questionnaireDateAddLData);
				but_questionnaireDateAdd.setText("\u65b0\u589e\u554f\u5377");
				but_questionnaireDateAdd.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_questionnaireDateAdd.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						if(txt_qTestDate.getText().equals("")){
							DialogCalendar dialogCalendar = new DialogCalendar(shell);
							int selectmonth = Integer.valueOf(cmb_month.getText());
							int selectyear = dateControl.getYearByMonth(Integer.valueOf(year), selectmonth);
							Object day = dialogCalendar.open(selectyear, selectmonth);
							if(day != null){
								if(dateControl.getDataYear(dateControl.getStringDate(day.toString())).equals(currentYear)){
									txt_qTestDate.setText(day != null ? day.toString() : txt_qTestDate.getText());
									but_questionnaireDateAdd.setFocus();
								}
							}
						}else{
							if(selectStudentNo != null){
								TableItem item = new TableItem(tableTestDate, SWT.NULL);
								item.setText(1, txt_qTestDate.getText());
							}
						}
					}
				});
			}
			{
				FormData but_questionnaireDeleteAllLData = new FormData();
				but_questionnaireDeleteAllLData.width = 132;
				but_questionnaireDeleteAllLData.height = 33;
				but_questionnaireDeleteAllLData.left =  new FormAttachment(0, 1000, 524);
				but_questionnaireDeleteAllLData.top =  new FormAttachment(0, 1000, 185);
				but_questionnaireDeleteAllLData.left =  new FormAttachment(0, 1000, 668);
				but_questionnaireDeleteAllLData.top =  new FormAttachment(0, 1000, 359);
				but_questionnaireDeleteAll = new Button(pageQuestionnaireComposite, SWT.NONE);
				but_questionnaireDeleteAll.setLayoutData(but_questionnaireDeleteAllLData);
				but_questionnaireDeleteAll.setText("\u6b64\u9801\u554f\u5377\u522a\u9664");
				but_questionnaireDeleteAll.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_questionnaireDeleteAll.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						if(DialogQuestion.open(shell, "確定刪除資料??","確定刪除資料??", SWT.ICON_QUESTION)){
							if(getQuestionnaires.deleteQuestionnaireByTestDatearg(tableQuestionnarie, year, selectTestDate, cmb_month.getText(), selectStudentNo)){
								DialogMessage.open(shell, "刪除成功", "刪除成功", SWT.ICON_INFORMATION);
								tableQuestionnarie.removeAll();
								tableQuestionnaireTestDateGetData();
								tableQuestionnaireGetData();
							}
						}
					}
				});
			}
			{
				FormData but_questionnaireSaveLData = new FormData();
				but_questionnaireSaveLData.width = 125;
				but_questionnaireSaveLData.height = 33;
				but_questionnaireSaveLData.left =  new FormAttachment(0, 1000, 828);
				but_questionnaireSaveLData.top =  new FormAttachment(0, 1000, 359);
				but_questionnaireSave = new Button(pageQuestionnaireComposite, SWT.NONE);
				but_questionnaireSave.setLayoutData(but_questionnaireSaveLData);
				but_questionnaireSave.setText("\u554f\u5377\u5132\u5b58");
				but_questionnaireSave.setFont(SWTResourceManager.getFont("Tahoma", 14, 1, false, false));
				but_questionnaireSave.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent e) {
						if(DialogQuestion.open(shell, "確定儲存資料??","確定儲存資料??", SWT.ICON_QUESTION)){
							if(getQuestionnaires.setQuestionnaireFromTable(tableQuestionnarie, year, selectTestDate, cmb_month.getText(), selectStudentNo)){
								DialogMessage.open(shell, "儲存成功", "儲存成功", SWT.ICON_INFORMATION);
								tableQuestionnarie.removeAll();
								tableQuestionnaireTestDateGetData();
								tableQuestionnaireGetData();
							}
						}
						
					}
				});
			}
		}
		return pageQuestionnaireComposite;
	}
	
	public void tableOneGetData(){
		List<Student> students = getStudents.getSpicalStudents(sno,
				year, grade, sclass);

		for (Student student : students) {
			Physical physical = getPhysicals.getSpicalStudentYearTestdatePhysicals(student.getStno(), year, cmb_date.getText());
			TableItem item = new TableItem(tableOne, SWT.NULL);
			item.setText(1, cmb_date.getText());
			item.setText(2, student.getStno());
			item.setText(3, student.getGrade());
			item.setText(4, student.getSclass());
			item.setText(5, String.valueOf(student.getClassno()));
			item.setText(6, student.getCname());
			item.setText(7, student.getSex());
			item.setText(8, String.valueOf(physical.getHeight()));
			item.setText(9, String.valueOf(physical.getWeight()));
			item.setText(10, String.valueOf(physical.getGrip()));
			item.setText(11, String.valueOf(physical.getJump()));
			item.setText(12, String.valueOf(physical.getSitup()));
			item.setText(13, String.valueOf(physical.getVcapacity()));
			item.setText(14, String.valueOf(physical.getRun69()));
			item.setText(15, String.valueOf(physical.getRun15()));
			if(physical.getBlock().equals("true")){
				item.setChecked(true);
			}
			if(physical.getHeight()!=0 & physical.getHeight()!=0 & physical.getWeight()!=0 & 
					physical.getGrip()!=0 & physical.getJump()!=0 & physical.getSitup()!=0 &
					physical.getVcapacity()!=0 ){
				item.setText(0, "完成");
			}
		}
	}
	
	public void tableStudentGetData(){
		List<Student> students = getStudents.getSpicalStudents(sno,
				year, grade, sclass);
		for (Student student : students) {
			TableItem item = new TableItem(tableStudent, SWT.NULL);
			item.setText(1, student.getGrade());
			item.setText(2, student.getSclass());
			item.setText(3, String.valueOf(student.getClassno()));
			item.setText(4, student.getCname());
			item.setText(5, student.getEname());
			item.setText(6, student.getStno());
		}
	}
	
	public void tableQuestionnaireTestDateGetData(){
		List<Date> testDates = new ArrayList<Date>();
		if(selectStudentNo != null){
			testDates = getQuestionnaires.getTestDateByYearMonthStno(selectStudentNo, year, cmb_month.getText());
		
			tableTestDate.removeAll();
			
			Iterator it = testDates.iterator();
            while(it.hasNext()) {
                Map testDateMap = (Map) it.next();
				TableItem item = new TableItem(tableTestDate, SWT.NULL);
				item.setText(1, dateControl.convertDate(testDateMap.get("TestDate").toString()));
			}
		}
	}
	
	public void tableQuestionnaireGetData(){
		if(selectStudentNo != null & selectTestDate != null){
			List<Question> questions = getQuestions.getQuestionByYear(year);
		    int i=0;
		    for(Question q : questions){
			
		        TableItem item = new TableItem(tableQuestionnarie, SWT.NULL);
			
		        List listAnswer = getQuestionnaires.getListAnswer(selectStudentNo, year, selectTestDate, q.getQno());
			
		        item.setText(0, q.getQno());
		        if(listAnswer != null){
		            Iterator it = listAnswer.iterator();
		            while(it.hasNext()) {
		                Map answerMap = (Map) it.next();
						item.setText(1, answerMap.get("Answer").toString());
		                }
		            }
		        
		            switch(item.getText(1)=="" ? 0 : Integer.valueOf(item.getText(1))) { 
		            case 1: 
		            	answerCombos[i].select(1);
				    	break;
				    case 2: 
				    	answerCombos[i].select(2);
				    	break;
				    case 3: 
				    	answerCombos[i].select(3);
				    	break;
				    case 4: 
				    	answerCombos[i].select(4);
				    	break;
				    default: 
				    	answerCombos[i].select(0);
				    	break;
				        }
		            answerEditors[i].setEditor(answerCombos[i], item, 1);
		            
		        i++;
		    }
		}
	}
	
	public void tableQuestionnairHide(){
		if(answerEditors!=null & answerCombos!=null){
			for(Combo answerCombo : answerCombos){
				answerCombo.setVisible(false);
			}
			for(TableItem item : tableQuestionnarie.getItems()){
				item.setText(1, "");
			}
		}
	}
	
	public void tableQuestionnairShow(){
		if(answerEditors!=null & answerCombos!=null){
			for(Combo answerCombo : answerCombos){
				answerCombo.setVisible(true);
			}
		}
	}
	
	public void tableQuestionnairSetup(){
		List<Question> questions = getQuestions.getQuestionByYear(year);
		answerEditors = new TableEditor[questions.size()];
		answerCombos = new Combo[questions.size()];
		int i=0;
		for(Question q : questions){
			
			final TableItem item = new TableItem(tableQuestionnarie, SWT.NULL);
			
			item.setText(0, q.getQno());
			
				String[] answerSelect = { "-", "沒有做", "很少做", "經常做", "天天做" };
				answerEditors[i] = new TableEditor(tableQuestionnarie);
				answerCombos[i] = new Combo(tableQuestionnarie, SWT.PUSH);
				answerCombos[i].computeSize(SWT.DEFAULT, 200);
				answerEditors[i].grabHorizontal = true;
				answerEditors[i].minimumHeight = answerCombos[i].getSize().y;
				answerEditors[i].minimumWidth = answerCombos[i].getSize().x;
				for (int loopIndex = 0; loopIndex < answerSelect.length; loopIndex++) {
					answerCombos[i].add(answerSelect[loopIndex]);
				}
				answerCombos[i].select(0);
				final int row = i;
				answerEditors[i].setEditor(answerCombos[i], item, 1);
				answerCombos[i].addSelectionListener(new SelectionAdapter() {
				      public void widgetSelected(SelectionEvent e) {
				    	  tableQuestionnarie.getItem(row).setText(1, String.valueOf(answerCombos[row].getSelectionIndex()));
				    	}
				      });
				if(!year.equals(currentYear)){
					answerCombos[i].setEnabled(false);
		        }else{
		        	answerCombos[i].setEnabled(true);
		        }
		    i++;
		}
		if(!year.equals(currentYear)){
			
        }else{
        	
        }
	}
	
	private void cmbLoad(){
		grades = getStudents.getAllGrade(sno, year, sclass);
		grades.add("All");
		sclasses = getStudents.getAllSclass(sno, year, grade);
		sclasses.add("All");
		testDates = getPhysicals.getAllTestDate(sno, year, grade, sclass);
		cmb_grade.removeAll();
		for (String str : grades) {
			cmb_grade.add(str);
		}
		cmb_class.removeAll();
		for (String str : sclasses) {
			cmb_class.add(str);
		}
		cmb_date.removeAll();
		for (String str : testDates) {
			cmb_date.add(str);
		}
		cmb_date.select(0);
	}
	
}
